package com.ww.microrpc;

import com.ww.microrpc.client.Client;
import com.ww.microrpc.netty.NettyClient;
import com.ww.microrpc.rpc.HystrixTargeter;
import com.ww.microrpc.rpc.MicroRpc;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class MicroRpcClientAutoConfiguration {

    @Bean
//    @Scope("prototype")
    @ConditionalOnMissingBean
    public MicroRpc.Builder microRpcBuilder() {
        return MicroRpc.builder();
    }


//    @Configuration(proxyBeanMethods = false)
//    @ConditionalOnClass({ HystrixCommand.class, HystrixMicroRpc.class })
//    protected static class HystrixMicroRpcConfiguration {
//
//        @Bean
//        @Scope("prototype")
//        @ConditionalOnMissingBean
//        @ConditionalOnProperty(name = "MicroRpc.hystrix.enabled")
//        public MicroRpc.Builder MicroRpcHystrixBuilder() {
//            return HystrixMicroRpc.builder();
//        }
//
//    }

    @Configuration(proxyBeanMethods = false)
//    @Conditional(MicroRpcCircuitBreakerDisabledConditions.class)
//    @ConditionalOnClass(name = "MicroRpc.hystrix.HystrixMicroRpc")
//    @ConditionalOnProperty(value = "MicroRpc.hystrix.enabled", havingValue = "true",
//            matchIfMissing = true)
    protected static class HystrixMicroRpcTargeterConfiguration {

        @Bean
        @ConditionalOnMissingBean
        public Targeter microRpcTargeter() {
            return new HystrixTargeter();
        }
    }

}
